<!--
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-03-23 16:59:58
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2023-03-24 08:24:43
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组去重</title>
</head>
<body>
    <script>
//    数组去重
let mg=[{name:123,age:456}, { name: 123, age: 456 },{ name: 1235, age: 456 },{name:1236,age:456}, { name: 1236, age: 456 }];

// 其实最主要的是设置一个中间变量或者对象属性值来判断如果是存在了就不再添加了
        let myArray = ['1', '2', '4', '5', '6', '7', '12', '3', '4', '5', '6', '7']
        let myArrayWithNoDuplicates = myArray.reduce(function (previousValue, currentValue) {
            if (previousValue.indexOf(currentValue) === -1) {
                previousValue.push(currentValue)
            }
            return previousValue
        }, [])

        console.log(myArrayWithNoDuplicates)
    </script>
</body>
</html>